from kafka import KafkaProducer
import requests
import pickle
# 1.创建KafkaProducer连接实例
producer = KafkaProducer(
    # 本地Kafka服务器的9092默认端口
    bootstrap_servers=['127.0.0.1:9092']
)
# 2.发送数据
total = 10
for i in range(1, total+1):
    url = f'http://www.techlabplt.com:8080/BD-PC/priceList?pageId={i}'
    response = requests.get(url)
    # 把对象序列化后以bytes对象返回。
    data = pickle.dumps(response)
    # 3. 定义topic为scrapy，并向此发送数据
    topic = 'scrapy'
    producer.send(topic, data)
# 3. 关闭连接
producer.close()
